package thread.内部api;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDe {


    public static void main(String[] args) {

        new ReentrantLockDe().test();

    }

    private void test() {
        ReentrantLock reentrantLock = new ReentrantLock();

        Condition condition = reentrantLock.newCondition();

        for (int i = 0; i < 4; i++) {
            int finalI = i;
            new Thread(() -> {
                reentrantLock.lock();

                try {
                    condition.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                reentrantLock.unlock();
                System.out.println("include  sum： " + finalI);

            }).start();
        }

        System.out.println("唤起");
        condition.signalAll();


    }


}
